<?php
/**
 * Created by cmb_weixin.master.
 * File: Customer.php
 * User: xuewl
 * Date: 2017/12/28
 * Time: 21:47
 */

namespace app\user\controller\admin;
use app\admin\controller\Backend;

class Customer extends Backend
{
    protected $model;
    public function _initialize()
    {
        parent::_initialize();
        $this->model = model('user/user', 'service');
    }

    public function selectpage()
    {
        $where = [
            'role' => 2,
        ];
        return parent::selectpage($where);
    }

    /**
     * 创建客户经理
     */
    public function create($id = 0) {
        if($this->request->isPost()) {
            $info = $this->request->param('row/a');
            $model = model('user/customer', 'service');
            $result = $model->create($this->request->param('id'), $info['code'], $info['realname'], $info['mobile']);
            if(!$result) {
                $this->error($model->getError());
            } else {
                $this->success('操作成功');
            }
        } else {
            $row = $this->model->find($id);
            return $this->view
                ->assign('row', $row)
                ->fetch();
        }
    }

    public function cancel() {
        $model = model('user/customer', 'service');
        $result = $model->cancel($this->request->param('id'));
        if(!$result) {
            return $this->error($model->getError());
        } else {
            return $this->success('操作成功');
        }
    }

}